home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <Xm/Xm.h>
- #include <X11/StringDefs.h>
- #include <Xm/Form.h>
- #include <Xm/SeparatoG.h>
- #include <Xm/List.h>
- #include <Xm/PushB.h>
- #include <Xm/Label.h>
- #include "exbookglo.h"
- #include "exinterfmotif.h"
- #include "exglobals.h"
-
- extern char *(extract_first_xms_segment() );
- extern struct indexlist *(find_keyword_int() );
-
- Widget Index_shell;
- Widget IndexList;
- Widget IndexLabel1, IndexLabel2;
- Widget IndexList1, IndexList2;
-
- void browseCB_Index(Widget w, XtPointer client_data, XtPointer call_data);
- void doneCB_Index(Widget w, XtPointer client_data, XtPointer call_data);
- void make_demo_list(Widget w, struct grptmpltstruct *grpptr);
- void make_keyword_list(Widget w, struct wordlist *keywords);
- void make_book_list(Widget w, struct icntmpltstruct *icnptr);
- void make_empty_list(Widget w);
- void make_list_of_demos(Widget w, struct indexlist *ndxptr);
- void make_list_of_groups(Widget w, struct indexlist *ndxptr);
-
- Widget create_Index()
- {
- Widget form, topform;
- Widget label, label1;
- Widget sep, form2, bottom_sep, done_button;
- Arg wargs[15];
- int n;
- XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
-
- Indexwin = -1;
- Index_shell = XtVaCreatePopupShell( "Indexshell",
- topLevelShellWidgetClass, DBtoplevel,
- XmNtitle, "Index",
- XmNallowShellResize, TRUE, NULL);
-
- n = 0;
- XtSetArg (wargs[n], XmNverticalSpacing, 10); n++;
- XtSetArg (wargs[n], XmNhorizontalSpacing, 10); n++;
- topform = XtCreateManagedWidget("IndexTopForm", xmFormWidgetClass,
- Index_shell, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNallowOverlap, FALSE); n++;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- form2 = XtCreateManagedWidget( "IndexForm2", xmFormWidgetClass,
- topform, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNverticalSpacing, 10); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- bottom_sep = XtCreateManagedWidget("Sep", xmSeparatorGadgetClass,
- form2, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopOffset, 10); n++;
- XtSetArg (wargs[n], XmNbottomOffset, 10); n++;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNtopWidget, bottom_sep); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- done_button = XtCreateManagedWidget( "DoneButton", xmPushButtonWidgetClass,
- form2, wargs, n);
- XtAddCallback( done_button, XmNactivateCallback, doneCB_Index, NULL);
-
- n = 0;
- XtSetArg (wargs[n], XmNverticalSpacing, 10); n++;
- XtSetArg (wargs[n], XmNhorizontalSpacing, 25); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNbottomWidget, form2); n++;
- form = XtCreateManagedWidget( "IndexForm", xmFormWidgetClass,
- topform, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNalignment, XmALIGNMENT_CENTER); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNtopOffset, 15); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- label = XtCreateManagedWidget("IndexLabel", xmLabelWidgetClass,
- form, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNbottomOffset, 15); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
- XtSetArg (wargs[n], XmNborderWidth, 1); n++;
-
- /* XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Legend:\nK Keyword\nD Demo Name\nB Book Name", charset)); n++; */
-
- label1 = XtCreateManagedWidget("LegendLabel", xmLabelWidgetClass,
- form, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNtopWidget, label); n++;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNbottomWidget, label1); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- IndexList = XmCreateScrolledList(form, "IndexList", wargs, n);
-
- XtManageChild(IndexList);
- XtAddCallback( IndexList, XmNbrowseSelectionCallback, browseCB_Index, NULL);
-
- n = 0;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNbottomWidget, form2); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNleftWidget, form); n++;
- XtSetArg (wargs[n], XmNorientation, XmVERTICAL); n++;
- sep = XtCreateManagedWidget("Sep", xmSeparatorGadgetClass,
- topform, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNleftWidget, sep); n++;
- XtSetArg (wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNbottomWidget, form2); n++;
- XtSetArg (wargs[n], XmNverticalSpacing, 5); n++;
- XtSetArg (wargs[n], XmNhorizontalSpacing, 25); n++;
- form = XtCreateManagedWidget( "IndexForm", xmFormWidgetClass,
- topform, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopOffset, 42); n++;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR(" ", charset)); n++;
- IndexLabel1 = XtCreateManagedWidget("IndexLabel1", xmLabelWidgetClass,
- form, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNtopWidget, IndexLabel1); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNvisibleItemCount, 5); n++;
- IndexList1 = XmCreateScrolledList(form, "IndexList1", wargs, n);
- XtManageChild(IndexList1);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNtopWidget, IndexList1); n++;
- XtSetArg (wargs[n], XmNtopOffset, 25); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR(" ", charset)); n++;
- IndexLabel2 = XtCreateManagedWidget("IndexLabel2", xmLabelWidgetClass,
- form, wargs, n);
-
- n = 0;
- XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg (wargs[n], XmNtopWidget, IndexLabel2); n++;
- XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg (wargs[n], XmNvisibleItemCount, 5); n++;
- IndexList2 = XmCreateScrolledList(form, "IndexList2", wargs, n);
- XtManageChild(IndexList2);
-
- XtRealizeWidget(Index_shell);
- SetWMhints(Index_shell);
- return(Index_shell);
- }
-
-
- #define KEYSIZE 7 /* char key + 5 spaces + comma */
- void update_index_win()
- {
- static long limit;
- static short nblocks = 0;
- static char *list = NULL;
- struct indexlist *ndxptr;
- long cumlength = 0;
- int count = 0;
- int blocksize = 1024;
- /* int i; */
-
- /* Display "working" dialog message. */
- sprintf(msgstring, "\nBuidling Index... Please wait\n");
- UxPopupInterface(create_Working(), no_grab);
- handleMotifInterfaceEvents();
-
- ndxptr = Index;
- if (list == NULL) {
- list = malloc(blocksize);
- limit = (1024 * nblocks)-9;
- nblocks = 1;
- }
- *list = '\0';
- /* for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- */
- /* strcpy(list, ""); */
- while (ndxptr != NULL)
- {
-
- #ifdef DEBUG
- fprintf(stderr,"%s\n",ndxptr->string);
- #endif
-
- count++;
- cumlength+=(strlen(ndxptr->string)+KEYSIZE);
- if (cumlength > limit)
- {
- nblocks++;
- list = (char *)realloc((void *)list, 1024*(nblocks));
- limit = (1024 * nblocks) - 1;
- }
- if (ndxptr->icon != NULL)
- strcat(list, "D ");
- else if (ndxptr->group != NULL)
- strcat(list, "B ");
- else
- strcat(list, "K ");
- strcat(list, (ndxptr->string));
- strcat(list, ",");
- ndxptr = ndxptr->next;
-
- }
-
- /* strcat(list, "\0"); */
-
- #ifdef DEBUG
- fprintf(stderr,"cumlength:%d strlen(list):%d\n",cumlength,strlen(list));
- #endif
-
- XtVaSetValues( IndexList,
- XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- #ifdef DEBUG
- fprintf(stderr,"Damn! made it past that XtVaSetGarbage call!\n");
- #endif
-
- /* Quit "working" dialog message. */
- UxPopdownInterface(Working);
- handleMotifInterfaceEvents();
-
- }
-
- void popup_Index()
- {
- update_index_win();
- Indexwin = 1;
- XtPopup(Index_w, XtGrabNone);
- }
-
- void doneCB_Index(Widget w, XtPointer client_data, XtPointer call_data)
- {
- Indexwin = -1;
- XtPopdown(Index_w);
- }
-
- void browseCB_Index(Widget w, XtPointer client_data, XtPointer call_data)
- {
- struct indexlist *found_word;
- char *my_string;
- int n;
- Arg wargs[2];
- XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
- int tmp;
- XmListCallbackStruct *callstruct;
-
- callstruct = (XmListCallbackStruct *)call_data;
- if (callstruct->reason == XmCR_BROWSE_SELECT)
- {
- my_string = extract_first_xms_segment(callstruct->item);
- tmp = callstruct->item_position-1;
- found_word = find_keyword_int(callstruct->item_position-1);
- /*I
- printf(" position %d word %s occur = %d\n", tmp, found_word->string,found_word->count);
- */
- if (found_word->group != NULL)
- {
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Demos in this Book", charset)); n++;
- XtSetValues(IndexLabel1, wargs, n);
- make_demo_list(IndexList1, found_word->group);
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Keywords of the Book", charset)); n++;
- XtSetValues(IndexLabel2, wargs, n);
- make_keyword_list(IndexList2, found_word->group->keywords);
- }
- else if (found_word->icon != NULL)
- {
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Keywords of this Demo", charset)); n++;
- XtSetValues(IndexLabel1, wargs, n);
- make_keyword_list(IndexList1, found_word->icon->keywords);
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Demo can be found in these Books", charset)); n++;
- XtSetValues(IndexLabel2, wargs, n);
- make_book_list(IndexList2, found_word->icon);
- }
- else
- {
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Demos with this Keyword", charset)); n++;
- XtSetValues(IndexLabel1, wargs, n);
- make_list_of_demos(IndexList1, found_word);
- n = 0;
- XtSetArg (wargs[n], XmNlabelString,
- XmStringCreateLtoR("Books with this Keyword", charset)); n++;
- XtSetValues(IndexLabel2, wargs, n);
- make_list_of_groups(IndexList2, found_word);
- }
- }
- }
-
- void make_empty_list(Widget w)
- {
- int count;
- char *list;
- int i;
- int blocksize = 2;
-
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
-
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
-
- void make_list_of_demos(Widget w, struct indexlist *ndxptr)
- {
- struct iconstruct *tmpicon;
- int count;
- char *list;
- int cumlength = 0;
- int len;
- int numalloc = 1;
- int i;
- int blocksize = 128;
-
- tmpicon = ndxptr->icons;
- if (tmpicon == NULL)
- make_empty_list(w);
- else
- {
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- while (tmpicon != NULL)
- {
- len = strlen(tmpicon->iconptr->nameptr->string);
- if (len+cumlength+1 > blocksize * numalloc - 2 )
- {
- numalloc++;
- list = realloc( (void *)list, blocksize * numalloc);
- }
- count++;
- cumlength+=(len+1);
- strcat(list, (tmpicon->iconptr->nameptr->string) );
- strcat(list, ",");
- tmpicon = tmpicon->nexticon;
- }
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
- }
-
- void make_list_of_groups(Widget w, struct indexlist *ndxptr)
- {
- struct grpliststruct *tmpgrpl;
- int count;
- char *list;
- int cumlength = 0;
- int len;
- int numalloc = 1;
- int i;
- int blocksize = 128;
-
- tmpgrpl = ndxptr->grps;
- if (tmpgrpl == NULL)
- make_empty_list(w);
- else
- {
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- while (tmpgrpl != NULL)
- {
- len = strlen(tmpgrpl->grpptr->nameptr->string);
- if (len+cumlength+1 > blocksize * numalloc - 2 )
- {
- numalloc++;
- list = realloc( (void *)list, blocksize * numalloc);
- }
- count++;
- cumlength+=(len+1);
- strcat(list, (tmpgrpl->grpptr->nameptr->string) );
- strcat(list, ",");
- tmpgrpl = tmpgrpl->next;
- }
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
- }
-
- void make_demo_list(Widget w, struct grptmpltstruct *grpptr)
- {
- int count;
- char *list;
- int cumlength = 0;
- int len;
- int numalloc = 1;
- struct pagestruct *tmppg;
- struct iconstruct *tmpicon;
- int i;
- int blocksize = 256;
-
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- tmppg = grpptr->firstpage;
- while(tmppg!= NULL)
- {
- tmpicon = tmppg->fronticons;
- /* list of demos is continuous from page to page, fron and back */
- while(tmpicon != NULL)
- {
- len = strlen(tmpicon->iconptr->nameptr->string);
- if (len+cumlength+1 > blocksize * numalloc - 2 )
- {
- numalloc++;
- list = realloc( (void *)list, blocksize * numalloc);
- }
- count++;
- cumlength+=(len+1);
- strcat(list, (tmpicon->iconptr->nameptr->string) );
- strcat(list, ",");
- tmpicon = tmpicon->nexticon;
- }
- tmppg = tmppg->nextpage;
- }
-
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
-
- void make_keyword_list(Widget w, struct wordlist *keywords)
- {
- int count;
- char *list;
- int len;
- int cumlength = 0;
- int numalloc = 1;
- struct wordlist *tmpkw;
- int i;
- int blocksize = 64;
-
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- tmpkw = keywords;
- while (tmpkw != NULL)
- {
- len = strlen(tmpkw->indexptr->string);
- if (len+cumlength+1 > blocksize * numalloc - 2 )
- {
- numalloc++;
- list = realloc( (void *)list, blocksize * numalloc);
- }
- count++;
- cumlength+=(len+1);
- strcat(list, (tmpkw->indexptr->string));
- strcat(list, ",");
- tmpkw = tmpkw->next;
- }
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
-
- void make_book_list(Widget w, struct icntmpltstruct *icnptr)
- {
- int count;
- char *list;
- int len;
- int cumlength = 0;
- int numalloc = 1;
- struct grpliststruct *tmpgrp;
- int i;
- int blocksize = 64;
-
- count = 0;
- list = malloc(blocksize * sizeof(char) );
- for (i = 0; i < blocksize; i++)
- list[i] = '\0';
- tmpgrp = icnptr->grps;
- while (tmpgrp != NULL)
- {
- len = strlen(tmpgrp->grpptr->nameptr->string);
- if (len+cumlength+1 > blocksize * numalloc - 2 )
- {
- numalloc++;
- list = realloc( (void *)list, blocksize * numalloc);
- }
- count++;
- cumlength+=(len+1);
- strcat(list, (tmpgrp->grpptr->nameptr->string));
- strcat(list, ",");
- tmpgrp = tmpgrp->next;
- }
- XtVaSetValues( w, XmNitemCount, count,
- RES_CONVERT(XmNitems, list),
- NULL);
- }
-
-
-